<template>
	<div class="personal">
		<el-form label-width="100px" ref="editForm" :model="editForm" :rules="rules">
			<el-form-item  label="课程名称" prop="kechengmingcheng"><el-input size="small" v-model="editForm.kechengmingcheng" auto-complete="off" placeholder="请输入课程名称" style='width:50%' disabled></el-input></el-form-item>
		<el-form-item  label="学分" prop="xuefen"><el-input size="small" v-model="editForm.xuefen" auto-complete="off" placeholder="请输入学分" style='width:50%' disabled></el-input></el-form-item>
		<el-form-item  label="用户名" prop="yonghuming"><el-input size="small" v-model="editForm.yonghuming" auto-complete="off" placeholder="请输入用户名" style='width:50%' ></el-input></el-form-item>
		<el-form-item  label="姓名" prop="xingming"><el-input size="small" v-model="editForm.xingming" auto-complete="off" placeholder="请输入姓名" style='width:50%' ></el-input></el-form-item>
		<el-form-item  label="成绩" prop="chengji"><el-input size="small" v-model="editForm.chengji" auto-complete="off" placeholder="请输入成绩" style='width:50%'></el-input></el-form-item>
		<el-form-item  label="工号" prop="gonghao"><el-input size="small" v-model="editForm.gonghao" auto-complete="off" placeholder="请输入工号" style='width:50%' ></el-input></el-form-item>
		<el-form-item  label="教师姓名" prop="jiaoshixingming"><el-input size="small" v-model="editForm.jiaoshixingming" auto-complete="off" placeholder="请输入教师姓名" style='width:50%'></el-input></el-form-item>
		
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">添加</el-button>
		</div>
	</div>
</template>

<script>
	import {chengjitianjiaEdit, chengjitianjiaSave,chengjitianjiaDetail} from "@/api/chengjitianjia/chengjitianjiaApi";
	import {Session} from "@/utils/storage";
import {kechengxuanzeDetail,kechengxuanzeEdit} from "../../api/kechengxuanze/kechengxuanzeApi";
//xiabiaoduan1
export default {
	name: 'personal',
	data() {
		return {
			rules: {
				//yztssssss1
			},
			editForm: {
				avater:'',
				kechengmingcheng:'',
				xuefen:'',
				yonghuming:'',
				xingming:'',
				
			},
			username:'',
			cx:'',
			//xiabiaoduan2
		};
	},
	created() {
		if (!Session.get('userInfo')) return false;
		this.userInfo = Session.get('userInfo');
		this.username=localStorage.getItem("username");
		this.cx=localStorage.getItem("cx");
		let id = this.$route.params.id;
		//xiabiaoduan3
		this.getUserInfo(id);
	},
	computed: {
		headers(){
			return {"token":Session.get("token")}
		},
	},
	methods:{
		getUserInfo(id){
			kechengxuanzeDetail(id).then(res=>{
				if(res.code == '0'){
					this.kechengxuanze = res.data
					this.editForm.kechengmingcheng = this.kechengxuanze.kechengmingcheng;
					this.editForm.xuefen = this.kechengxuanze.xuefen;
					// this.editForm.yonghuming = this.kechengxuanze.yonghuming;
					// this.editForm.xingming = this.kechengxuanze.xingming;
          //
					// this.editForm.gonghao= this.userInfo.gonghao;
					
					// this.editForm.jiaoshixingming= this.userInfo.jiaoshixingming;
				
				}
			})
		},
		
		//qixuzhijixsuan3
		//xia2sui1
		// 编辑、增加页面保存方法
		submitForm(editData) {
			
			this.$refs[editData].validate(valid => {
				if (valid) {
					if(this.editForm.id){
						
					}else {
						chengjitianjiaSave(this.editForm).then(res => {
							if (res.code == '0') {
								
								this.$message({
									type: 'success',
									message: '添加成功！'
								})
							} else {
								this.$message({
									type: 'info',
									message: res.msg
								})
							}
						}).catch(err => {
							if(err){
								this.$message.error(err)
							}else {
								this.$message.error('操作失败，请稍后再试！')
							}
						})
					}
				} else {
					return false
				}
			})
		},
		
		//youscwexnjiaxn
		//xiabiaoduan4
	}
};
</script>

<style scoped lang="scss">
	@import './index.scss';
</style>
